//
//  MessageCircleDetailTableViewCell.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/2/7.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit

class MessageCircleDetailTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, BottomShadow {
    
    let imageSize: CGFloat = 79
    @IBOutlet weak var mainView: BaseCircleView!
    @IBOutlet weak var titleLabelHeight: NSLayoutConstraint!
    @IBOutlet weak var contentLabelHeight: NSLayoutConstraint!
    @IBOutlet weak var contentLabelBottom: NSLayoutConstraint!
    @IBOutlet weak var imagesCollectionViewBottom: NSLayoutConstraint!
    @IBOutlet weak var imagesCollectionView: UICollectionView!
    
    @IBOutlet weak var headerImage: BaseCircleImageView!
    
    @IBOutlet weak var titleLable: UILabel!
    @IBOutlet weak var contentTitleLable: UILabel!
    @IBOutlet weak var timeLable: UILabel!
    @IBOutlet weak var contentLable: UILabel!
    
    @IBOutlet weak var likeButton: UIButton!
    
    @IBOutlet weak var commentButton: UIButton!
    
    var circleDetail: circleDetailListModel?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
    }
    
    func setUI() {
        imagesCollectionView.delegate = self
        imagesCollectionView.dataSource = self
        imagesCollectionView.register(UINib(nibName: "\(CommentCollectionViewCell.self)", bundle: nil), forCellWithReuseIdentifier: "cell")
        imagesCollectionView.showsHorizontalScrollIndicator = false
        
        let followLayout = UICollectionViewFlowLayout()
        followLayout.minimumInteritemSpacing = 10
        followLayout.scrollDirection = .horizontal
        followLayout.itemSize = CGSize(width: imageSize + 20, height: imageSize)
        imagesCollectionView.collectionViewLayout = followLayout
        
        imagesCollectionViewBottom.priority = .defaultHigh
        contentLabelBottom.priority = .defaultLow
        imagesCollectionView.isHidden = true
        setShadow(view: mainView, opacity: bottomShadowOpacity, size: bottomShadowOffset, color: UIColor.black, cornerradius: CORNERRADIUS)
    }
    
    func bindData(data: circleDetailListModel?){
        if data != nil {
            circleDetail = data
            if data?.author != nil{
                let url: String? = "\(BaseURL)" + (data?.author?.headIcon)!
                headerImage.sd_setImage(with: NSURL.init(string: url!) as URL?, completed: nil)
                titleLable.text = data?.author?.nickname
            }
            contentTitleLable.text = data?.title
            if data?.label?.name != "null" {
                contentLable.text = data?.label?.name
            }
            timeLable.text = data?.publishTime
            likeButton.setTitle(data?.collected, for: .normal)
            commentButton.setTitle(data?.comment, for: .normal)
        }
        
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? CommentCollectionViewCell
        cell?.bindData(data: circleDetail!)
        return cell!
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
